package com.threeonemeeting.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.threeonemeeting.R;
import com.threeonemeeting.list.CityInfoList;
import com.threeonemeeting.model.CityInfo;

public class CityNameListAdapter extends ArrayAdapter<CityInfo> {

	private CityInfoList mCitysItems = null;

	public void setCitysList(CityInfoList citysList) {
		mCitysItems = citysList;
		notifyDataSetChanged();
	}

	public CityInfoList getCityList() {
		return mCitysItems;
	}

	@Override
	public void add(CityInfo cityInfo) {
		if (mCitysItems == null)
			mCitysItems = new CityInfoList();

		mCitysItems.addCityInfo(cityInfo);
	}

	public void clear() {
		if (mCitysItems != null) {
			mCitysItems.clear();
		}
	}

	@Override
	public int getCount() {
		if (mCitysItems == null)
			return 0;

		return mCitysItems.size();
	}

	@Override
	public CityInfo getItem(int position) {
		return mCitysItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public CityNameListAdapter(Activity activity) {
		super(activity, 0);
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		Activity activity = (Activity) getContext();
		CityInfo info = getItem(position);

		View rowView = convertView;
		LayoutInflater inflater = activity.getLayoutInflater();
		rowView = inflater.inflate(R.layout.lvi_trade, null);

		// 会议标题
		TextView meetingTitleView = (TextView) rowView
				.findViewById(R.id.tx_category_name);
		meetingTitleView.setText(info.strCityName);

		return rowView;
	}

}
